﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ShopB2C.Core.Helpers;
using System.Web.Routing;

namespace XTeam.Core.Helper
{
    public static class MvcPager
    {
        /// <summary>
        /// 页码显示
        /// </summary>
        /// <param name="html">Html</param>
        /// <param name="pagerEntity">页码属性匿名类型，其中可以用的字符串为:PageIndex:当前索引,PageCount:总页数
        /// HrefFormat:链接到格式化字符串，占用{格式化字符串{0}占位符,请注意字符转义,FirstPageText,LastPageText,PageUpText,PageDownText</param>
        /// <returns>可以在浏览器打印的Html</returns>
        public static string Pager(object pagerEntity)
        {
            RouteValueDictionary propertys = new RouteValueDictionary(pagerEntity);

            return Pager(new WebPagerHelper()
            {
                PageIndex = propertys["PageIndex"] != null ? Convert.ToInt32(propertys["PageIndex"]) : 1,
                PageCount = propertys["PageCount"] != null ? Convert.ToInt32(propertys["PageCount"]) : 0,
                TotalRows = propertys["TotalRows"] != null ? Convert.ToInt32(propertys["TotalRows"]) : 0,
                PageSize = propertys["PageSize"] != null ? Convert.ToInt32(propertys["PageSize"]) : 15,

                FirstPageText = propertys["FirstPageText"] != null ? propertys["FirstPageText"].ToString() : null,
                LastPageText = propertys["LastPageText"] != null ? propertys["LastPageText"].ToString() : null,

                PageUpText = propertys["PageUpText"] != null ? propertys["PageUpText"].ToString() : null,
                PageDownText = propertys["PageDownText"] != null ? propertys["PageDownText"].ToString() : null,

                HrefFormat = propertys["HrefFormat"] != null ? propertys["HrefFormat"].ToString() : null,
            });

        }
        /// <summary>
        /// 页码显示
        /// </summary>
        /// <param name="html">Html</param>
        /// <param name="pageHelper">PagerHelper实体</param>
        /// <returns>可以在浏览器打印的Html</returns>
        private static string Pager(WebPagerHelper pageHelper)
        {
            return pageHelper.CreateHtml();
        }

    }



}
